<!--点赞-->
<template>
  <div @click.stop="up">
    <span class="icon-up icon-like" :class="{'icon-liked':hasUp}"></span>
    {{data.ups || 0}}
  </div>
</template>

<script>
  export default {
    name: '',
    props: ['commentId', 'contentId', 'upsCount', 'option'],
    components: {},
    data () {
      return {
        data: {
          ups: 0
        },
        hasUp: false
      }
    },
    created () {
//      this.loadData()
      this.data.ups = this.upsCount
      this.hasUp = this.option.support
    },
    methods: {
      loadData () {
        let params = {
          contentId: this.contentId,
          commentId: this.commentId
        }
        return this.fetchService.upsOrDownsPage(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.data = res.data
          return res
        })
      },
      up () {
        if (this.hasUp === true) {
          return false
        }
        let userInfo = this.$localStorage.get('userInfo')
        let params = {
          spaceId: this.commentId,
          loginId: userInfo.id
        }
        return this.fetchService.saveSpaceInfoSupport(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.hasUp = true
          this.data.ups ++
          return res
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .title.link-arrow.link {
    border-color:#eeeeee;
    &.active {
      border-color:#0f9ceb;
    }
  }
</style>
